package lv.yasa.helper;

import java.io.File;
import java.util.HashMap;
import java.util.Map;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Environment;

public class FSHelper {
	static Map<String, Bitmap> bitmaps;
	
	public static void init()
	{
		bitmaps = new HashMap<String, Bitmap>();
	}
	
	public static String getFilePath(String name)
	{
		return Environment.getExternalStorageDirectory() + "/yasa/" + name;
		//return "/sdcard/yasa/" + name;
	}
	
	public static File getFile(String name)
	{
		File f = new File(getFilePath(name));
		
		return f;
	}
	
	public static Bitmap getFileBitmap(String name)
	{
		File f = getFile(name);
		
		if (f.exists())
		{			
			String path = getFilePath(name);
			if (bitmaps.containsKey(path))
			{
				return bitmaps.get(path);
			}
			else
			{
				Bitmap b = BitmapFactory.decodeFile(path);
		    	bitmaps.put(path, b);
		    	return b;
			}
		}
		return null;
	}
}
